import React, {useState} from 'react';
import {StyleSheet} from 'react-native';
import {Button, View} from '@ant-design/react-native';
import useStorage from '../../hooks/storage';
import {TUserInfo} from '../../type/TUser';
import HasLogin from './LoginPlan';

const NoLogin = ({navigation}) => {
  const goLogin = () => {
    navigation.push('登录');
  };
  return (
    <View style={styles.user}>
      <Button type="primary" onPress={goLogin}>
        去登录
      </Button>
    </View>
  );
};

const User = ({navigation}) => {
  //   const nav = useNavigation();
  const storage = useStorage<TUserInfo>('userInfo');
  let [userInfo, setUserInfo] = useState<TUserInfo | null>(null);
  storage.getItem().then(res => {
    setUserInfo(res);
  });
  return (
    <View style={styles.user}>
      {userInfo ? (
        <HasLogin navigation={navigation} userInfo={userInfo} />
      ) : (
        <NoLogin navigation={navigation} />
      )}
    </View>
  );
};
const styles = StyleSheet.create({
  user: {
    padding: 10,
  },
});
export default User;
